package net.xuele.learn.IO.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Created by GaoQingming on 2019/4/10 0010.
 */
public class TimeClient {
    public static void main(String[] args) throws IOException {
        int port  = 7777;
        Socket socket = null;
        BufferedReader in = null;
        PrintWriter out = null;
        try {
            // 这一步调用了socket函数，connect函数
            socket = new Socket("127.0.0.1",port);
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream(),true);
            // 向服务端发送信息
            out.println("QUERY TIME ORDER");
            System.out.println("send order 2 server successfully");
            // 读取服务端的信息
            String resp = in.readLine();
            System.out.println("NOW is:"+resp);
        } catch (Exception e) {

        } finally {
            if (out!=null) {
                out.close();
                out=null;
            }
            if (in != null) {
                in.close();
            }
            if (socket != null){
                socket.close();
            }
        }
    }
}
